<template>
  <div :class="isActiveClass" :style="defaultStyle">
    <div class="navList" :style="contentStyle">
      <div
        class="category-item"
        v-for="(item, index) in contentData.default_sub_list"
        :key="index"
        :style="itemStyle"
      >
        <div><img :style="imgStyle" :src="item.fileUrl" class="img" /></div>
        <div class="text-area" :style="titleItemStyle" v-if="contentData.show_name">{{
          item.fileName
        }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  const props = defineProps({
    contentData: {
      type: Object,
      default() {
        return {}
      }
    },
    isActiveClass: {
      type: String
    }
  })

  const defaultStyle = computed(() => {
    const s = props.contentData.style
    return {
      paddingTop: s.paddingTop,
      paddingLeft: s.paddingLeft,
      paddingRight: s.paddingRight,
      paddingBottom: s.paddingBottom
    }
  })

  const contentStyle = computed(() => {
    const s = props.contentData.style
    return {
      borderRadius: s.borderRadius,
      backgroundColor: s.backgroundColor
    }
  })

  const imgStyle = computed(() => {
    const s = props.contentData.itemStyle
    return {
      borderRadius: s.borderRadius !== 100 ? s.borderRadius + 'px' : '50%',
      width: s.width ? s.width + 'px' : '30px',
      height: s.width ? s.width + 'px' : '30px'
    }
  })

  const itemStyle = computed(() => {
    const count = props.contentData.show_num || 4
    return {
      flex: `0 0 ${100 / count}%`
    }
  })

  const titleItemStyle = computed(() => {
    const s = props.contentData.itemStyle
    return {
      ...s,
      fontSize: s.fontSize + 'px',
      fontWeight: s.fontWeight === 0 ? 'normal' : s.fontWeight
    }
  })
</script>

<style scoped lang="scss">
  .navList {
    display: flex;
    flex-wrap: wrap;
    box-sizing: border-box;

    .category-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 10px 5px;
      box-sizing: border-box;

      .title {
        margin-top: 4px;
        font-size: 14px;
      }

      .text-area {
        margin-top: 3px;
      }
    }
  }

  .active-component {
    border: 1px solid var(--el-color-primary);
  }
</style>
